<html>
	
		<script type="text/javascript">
		
		//var prefs = new _IG_Prefs();
		
		function fetch(groupId)
		{
			alert(groupId);
			var numSelector = 'course_num'+groupId;
			var year = document.getElementById('year').value;
			var semester = document.getElementById('semester').value;
			var course_num = document.getElementById(numSelector).value;
			//alert(course_num);
			var divToChange = "groups"+groupId;
			var url = "getPage.php?";
			if ('' == course_num)
			{
				alert('please enter a course num!');
				return false;
			}
			if (8 != course_num.length)
			{
				alert('please enter a full course number of 8 digits');
				return false;
			}
			var pageRequest = false;
			if (window.XMLHttpRequest) pageRequest = new XMLHttpRequest();
			else if (window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
			else
				return false;
			var params = "MfcISAPICommand=but&serial="+groupId+"&year="+year+"&course_num="+course_num+'&semester="'+semester+'"';
			url += params;
			alert(url);
			pageRequest.open("GET", url, true);
			pageRequest.onreadystatechange = function()
			{
				if(pageRequest.readyState == 4 && pageRequest.status == 200)
				{
					var testDiv = document.getElementById(divToChange);
					testDiv.innerHTML = pageRequest.responseText;
					alert(pageRequest.responseText);
				}
			}
			pageRequest.send(params);
		}
		function addSite(courseName,groupId,value)
		{
			var toTransmit = "site"+groupId+"|"+courseName+"|"+value;
			alert(toTransmit);
		}
		/* from GOOGLE
		function fetch(groupId)
		{ 
			var numSelector = 'course_num'+groupId;
			var year = document.getElementById('year').value;
			var semester = document.getElementById('semester').value;
			var url = "http://www.wssolutions.co.il/tautab/getPage.php?";
			var course_num = document.getElementById(numSelector).value;
			var divToChange = "groups"+groupId;
			if ('' == course_num) 
			{
				alert('please enter a course num!');
				return false;
			}
			if (8 != course_num.length)
			{
				alert('please enter a full course number of 8 digits');
				return false;
			}
			url += "MfcISAPICommand=but&serial="+groupId+"&year="+year+"&course_num="+course_num+'&semester="'+semester+'"';
			_IG_FetchContent(url, function handleResponse(response)
													{
														//alert('here');
														alert('response=  '+response+ 'end of response' );
														document.getElementById(divToChange).innerHTML = response; });
		}
		*/
		function addNewCourse()
		{
			var oldCourseNum = document.getElementById('currentCourseNum').value;
			if ('' == document.getElementById('course_num'+oldCourseNum))
			{
				alert('please fill up current course first');
				return false;
			}
			doDisable(oldCourseNum);
			var newCourseNum = ++oldCourseNum;
			//prefs.set("test000",newCourseNum);
			document.getElementById('currentCourseNum').value = newCourseNum;
			var divToChange = 'add'+newCourseNum;
			updateDiv(divToChange,newCourseNum);
			
		}
		function doDisable(groupId)
		{
			var oldLecId = 'lec'+groupId;
			var oldRecId = 'rec'+groupId;
			var oldSearchId = 	'search'+groupId;
			document.getElementById(oldLecId).disabled=true;
			document.getElementById(oldRecId).disabled=true;
			document.getElementById(oldSearchId).disabled=true;
		}
		function updateDiv(divId,groupId)
		{
			var html ="<div class=addCourse id="+divId+"><div class=addCourseCell>";
			html +="<input class=inputText type=text id=course_num"+groupId+" value=''>";
			html +="</div>";
			html +="<div class=groupsCell id=groups"+groupId+">";
			html +="<div class=groupsLectureCell id=lecCell"+groupId+">";
			html +="<select id=lec"+groupId+" disabled class=inputSelect></select>";
			html +="</div>";
			html +="<div class=groupesRecCell id=recs"+groupId+">";
			html +="<select id=rec"+groupId+" disabled class=inputSelect></select>";
			html +="</div></div>";
			html +="<div class=searchCell>";
			html +="<input id=search"+groupId+" class=inputSearch";
			html +=" value=Search type=button onclick=\"fetch("+groupId+");\"/>";
			html +="</div></div>";
			document.getElementById(divId).className="addCourse";
			document.getElementById(divId).innerHTML=html;
		}
		/*
		function transmit(selectObj)
		{
			//alert(selectObj.value);
			var nextOpen =  prefs.getString("test000");
			//++nextOpen;
			//alert(nextOpen);
			prefs.set("test000",nextOpen);
			var courseToChange = "test00"+nextOpen;
			prefs.set(courseToChange,selectObj.value);
			//alert("transmitting "+prefs.getString(courseToChange));
			
			<UserPref name="test000" display_name="lastUpdatedCourse" default_value="0" publish="true" /> 
			<UserPref name="test001" display_name="course1" default_value="" publish="true" />
			<UserPref name="test002" display_name="course2" default_value=""  publish="true" />
			<UserPref name="test003" display_name="course3" default_value="" publish="true" />
			<UserPref name="test004" display_name="course4" default_value="" publish="true" />
			<UserPref name="test005" display_name="course5" default_value="" publish="true" />
			<UserPref name="test006" display_name="course6" default_value="" publish="true" />
			<UserPref name="test007" display_name="course7" default_value="" publish="true" />
			<UserPref name="test008" display_name="course8" default_value="" publish="true" />
			<UserPref name="test009" display_name="course9" default_value="" publish="true" />
			
			
		}
		*/
		
		</script>
		<style>
		div.generalStuff
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			font-family:arial;
			font-size:12px
			width:400px;
			align:center;
		}
		div.headerRow
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:270px;
			height:20px;
			font-family:arial;
			font-size:11px;
			/*border:1px solid black;*/
		}
		div.headerCell
		{
			position:relative;
			float:left;
			width:90px;
			font-family:arial;
			font-size:12px;
			top:0px;
			left:0px;
			align:center;
			vertical-align:center;
		}
		div.addCourse
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:330px;
			/*border:1px solid blue;*/
			
		}
		div.addCourseCell
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:90px;
			font-family:arial;
			font-size:12px;
			align:center;
		}
		div.groupsCell
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:180px;
		}
		div.groupsLectureCell
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:90px;
			align:center;
		}
		dic.groupesRecCell
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:90px;
			align:center;
		}
		div.searchCell
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:60px;
			align:center;
			
		}
		div.hiddenDiv
		{
			position:relative;
			float:left;
			top:0px;
			left:0px;
			width:0px;
			hight:0px;
		}
		input.inputText
		{
			width:90%;
			font-size:12px;
			font-family:arial;
			
		}
		select.inputSelect
		{
			width:50px;
			font-size:12px;
			font-family:arial;
		}
		input.inputSearch
		{
			font-size:12px;
			font-family:arial;	
		}
		</style>
		
	</head>
	<body>
	<div class=generalStuff>
			year:
				<select name=year id=year>
					<option value=2007>2007/8</option>
					<option value=2006>2006/7</option>
				</select>
			semester:
				<select name=semester id=semester>
					<option value="aa">winter</option>
					<option value="bb">spring</option>
				</select>
		</div>
		<br/>
		<div class=headerRow>
			<div class=headerCell id=courseCell>Course Num</div>
			<div class=headerCell id=lecCell>Lecture Grp</div>
			<div class=headerCell id=recCell>Rec' Grp</div>
		</div>
		<br/>
		<div class=addCourse id=add1>
			<div class=addCourseCell>
				<input class=inputText type=text name=course_num1 id=course_num1 value=''>
			</div>
			<div class=groupsCell id=groups1>
				<div class=groupsLectureCell id=lecCell1>
					<select id=lec1 name=lec1 disabled class=inputSelect></select>
				</div>
				<div class=groupesRecCell id=recs1>
					<select id=rec1 name=rec1 disabled class=inputSelect></select>
				</div>
			</div>
			<div class=searchCell>
				<input id=search1 class=inputSearch value="Search" type=button onclick="fetch(1);"/>
			</div> 
		</div>
		<br>
		<div class=hiddenDiv id=add2></div>
		<div class=hiddenDiv id=add3></div>
		<div class=hiddenDiv id=add4></div>
		<div class=hiddenDiv id=add5></div>
		<div class=hiddenDiv id=add6></div>
		<div class=hiddenDiv id=add7></div>
		<div class=hiddenDiv id=add8></div>
		<br>
		<input type=button value="add new course" onclick="addNewCourse();"/>
		<input type=hidden value=1 name=currentCourseNum id=currentCourseNum />
		
		
	</body>
</html>
